package com.example.foobar.controller;

import com.example.foobar.business.service.DaRemarkService;
import com.example.foobar.entity.DaRemark;
import com.example.foobar.param.DaRemarkPageParam;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 备注 控制器
 *
 * @author 郑英奔
 * @since 2021-06-07
 */
@Slf4j
@RestController
@RequestMapping("/daRemark")
@Module("foobar")
@Api(value = "备注API", tags = {"备注"})
public class DaRemarkController extends BaseController {

    @Autowired
    private DaRemarkService daRemarkService;

    /**
     * 添加备注
     */
    @PostMapping("/add")
    @OperationLog(name = "添加备注", type = OperationLogType.ADD)
    @ApiOperation(value = "添加备注", response = ApiResult.class)
    public ApiResult<Boolean> addDaRemark(@Validated(Add.class) @RequestBody DaRemark daRemark) throws Exception {
        boolean flag = daRemarkService.saveDaRemark(daRemark);
        return ApiResult.result(flag);
    }

    /**
     * 修改备注
     */
    @PostMapping("/update")
    @OperationLog(name = "修改备注", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改备注", response = ApiResult.class)
//    "uniacid" : data.uniacid,
//            "date": data.date,
//            "remark" : data.remark
    public ApiResult<Boolean> updateDaRemark(int uniacid, Date date, String remark) throws Exception {
        boolean flag = daRemarkService.updateDaRemark(uniacid, date, remark);
        return ApiResult.result(flag);
    }

    /**
     * 删除备注
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除备注", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除备注", response = ApiResult.class)
    public ApiResult<Boolean> deleteDaRemark(@PathVariable("id") Long id) throws Exception {
        boolean flag = daRemarkService.deleteDaRemark(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取备注详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "备注详情", type = OperationLogType.INFO)
    @ApiOperation(value = "备注详情", response = DaRemark.class)
    public ApiResult<DaRemark> getDaRemark(@PathVariable("id") Long id) throws Exception {
        DaRemark daRemark = daRemarkService.getById(id);
        return ApiResult.ok(daRemark);
    }


}

